<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html class="no-js">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>沃店</title>
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/amazeui.min
.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/app.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/index.css">
    <!--必要样式-->
    <style type="text/css">
        body {
            background-color: #fff;
        }

        .title {
            padding: 5px 0px;
            text-align: center;
        }

        .input-type {
            height: 35px;
            width: 100%;
            border: none;
        }

        .money {
            padding: 10px;
            margin-top: 10px;
            float: left !important;
        }

        .money div {
            border: 1px #ED6D00 solid;
            padding: 5px 10px;
            border-radius: 5px;

        }

        .money-active {
            background-color: #ed6d00 !important;
            color: #fff;
        }

        .type {
            margin-left: 10px;
            font-size: 14px;
        }

        .recharge {
            border: 1px #ed6d00 solid;
            width: 70%;
            margin-top: 40px;
            background-color: #ed6d00;
            color: #fff;
            padding: 5px 0;
            border-radius: 5px;
        }
    </style>
</head>

<body>
<header data-am-widget="header" class="am-header am-header-default am-header-fixed">
    <div class="am-header-left am-header-nav">
        <a href="#left-link" class="">
            <i class="am-header-icon am-icon-chevron-left"></i>
        </a>
    </div>
    <h1 class="am-header-title">
        <a href="#title-link" class="">
            流量充值
        </a>
    </h1>
</header>
<form action="${pageContext.request.contextPath}/clientTraffic/order" id="sub">
    <div class="am-g whiteBg" style="padding: 5px 0;border-bottom: 2px #f6f6f6 solid;">
        <div class="am-u-sm-3 title">
            手机号
        </div>
        <div class="am-u-sm-9 ">
            <input type="text" class="input-type" name="phone" style="border: 1px #ccc solid;">
        </div>

    </div>
    <input type="hidden" value="" id="trafficId" name="id">
    <div class="am-g" id="moneylist">
        <div class="am-u-sm-12">
            <span class="type">{{items.type}}</span>
        </div>

        <div v-on:click="bindMoneyClick" class="am-u-sm-4 money " align="center" v-for="item in items.list">
            <div><span>{{item.description}}</span><br><span
                    style="font-size: 12px;">{{item.price}}元</span>
                <input type="hidden" v-model="item.id">
            </div>
        </div>

    </div>
</form>
<div class="am-u-sm-12" align="center">
    <div class="recharge" onclick="sub()">确认充值</div>
</div>
<!--[if (gte IE 9)|!(IE)]><!-->
<script src="${pageContext.request.contextPath}/assets/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/amazeui.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/vue.js"></script>
<script src="${pageContext.request.contextPath}/layer/layer.js"></script>
<script type="text/javascript">
    $(function () {

        $('.input-type').bind('input propertychange', function () {
            if ($(this).val().length == 11) {
                getMoneyList();
            }
        });
    });

    var moneyList = new Vue({
        el: "#moneylist",
        data: {
            items: {
                type: "",
                list: []
            }
        },
        methods: {
            bindMoneyClick: function () {
                $(".money").click(function () {
                    $(".money div").removeClass("money-active");
                    $(this).find("div").addClass("money-active");
                });
            }
        }
    });


    function getMoneyList() {
        var phone = $(".input-type").val();
        $.ajax({
            type: "post",
            url: '${pageContext.request.contextPath}/clientTraffic/findByPhone',
            data: {
                phone: phone
            },
            dataType: 'json',
            success: function (data) {
                if (data.success == true) {
                    moneyList.items.list = data.obj;

                    if (moneyList.items.list[0].type == 1) {
                        moneyList.items.type = "中国联通";
                    } else if (moneyList.items.list[0].type == 2) {
                        moneyList.items.type = "中国移动";
                    } else if (moneyList.items.list[0].type == 3) {
                        moneyList.items.type = "中国电信";
                    }
                } else {
                    moneyList.items.type = data.msg;
                }

            },
            error: function () {
                layer.msg('网络超时');
            }

        });

    }
    function sub() {
        var id = $(".money-active input").val();
        $("#trafficId").val(id);
        var phone = $(".input-type").val();

        if (phone == '') {
            layer.msg("请输入手机号！");
            return;
        }
        if (id == '' || typeof(id) == 'undefined') {
            layer.msg("请选择流量套餐！");
            return;
        }

        $("#sub").submit();
    }
</script>
</body>

</html>
